import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { getMovieList } from "../../api/api";

export const getMovieAct = createAsyncThunk("movie/getMovie", async () => {
  const re = await getMovieList();
  return re.data.data.list;
});

const movieSlice = createSlice({
  name: "movie",
  initialState: {
    movieList: [],
  },
  reducers: {},
  extraReducers: {
    [getMovieAct.fulfilled](preState, action) {
      preState.movieList = action.payload;
      console.log("成功");
    },
    [getMovieAct.rejected]() {
      console.log("加载失败");
    },
    [getMovieAct.pending]() {
      console.log("正在加载");
    },
  },
});

export default movieSlice.reducer;
